package anji.plus.system.mark.controller;

import anji.plus.system.mark.base.BaseController;
import anji.plus.system.mark.base.Header;
import anji.plus.system.mark.base.IBaseService;
import anji.plus.system.mark.domain.Flag;
import anji.plus.system.mark.domain.SysUser;
import anji.plus.system.mark.response.ResponseResult;
import anji.plus.system.mark.service.IFlagService;
import anji.plus.system.mark.utils.LoginUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * <p>
 * flag表 前端控制器
 * </p>
 *
 * @author zhouchong
 * @since 2023-12-26
 */
@RestController
@RequestMapping("sys/flag")
public class FlagController extends BaseController {


    @Resource
    private IFlagService flagService;

    @Resource
    LoginUtils loginUtils;

    @Override
    public IBaseService getService() {
        return null;
    }

    /**
     * 方法实现说明 查询flag信息
     *
     * @return
     * @throws
     * @author terry
     * @date 2022/5/31 11:47
     */
    @GetMapping({"queryFlagList"})
    public ResponseResult queryFlagList(String name) {
        return ResponseResult.success(flagService.queryFlagList(name));
    }

    @GetMapping({"queryTeamFlag"})
    public ResponseResult queryTeamFlag() {
        return ResponseResult.success(flagService.queryFlagList());
    }

    @PostMapping({"addFlag"})
    public ResponseResult addFlag(@RequestBody Flag flag) {
        flagService.addFlag(flag);
        String token = Header.getAuthorization(request.getHeader("Authorization"));
        SysUser sysUser = loginUtils.get(token);
        System.out.println("********************");
        System.out.println(sysUser.getFullname());
        System.out.println("********************");
        return ResponseResult.success("添加成功");
    }

    @PostMapping({"updateFlag"})
    public ResponseResult updateFlag(@RequestBody Flag flag) {
        flagService.updateFlag(flag);
        return ResponseResult.success("更新成功");
    }

    @GetMapping({"likeFlag"})
    public ResponseResult likeFlag() {
        return ResponseResult.success(flagService.likeFlag());
    }

    @DeleteMapping({"deleteFlag"})
    public ResponseResult deleteFlag(String id) {
        flagService.deleteFlag(id);
        return ResponseResult.success("删除成功");
    }


}


